package com.gitee.wsl.io.dataproxy

open class DataGetWarp<T>(
    open val base: DataGet<T>,
    val indexList: List<Int>,
    override val size: Int = indexList.size): DataGet<T> {
    constructor(base: DataGet<T>, intRange: IntRange):this(base,intRange.toList())
    constructor(base: DataGet<T>, vararg index:Int):this(base,index.toList())

    override fun get(index: Int): T = base[indexList[index]]

    override fun values(): List<T> = indexList.map{ base[indexList[it]] }

}

fun<T> DataGet<T>.asProxy(intRange: IntRange) = DataGetWarp(this,intRange)

fun<T> DataGet<T>.asProxy(vararg index:Int) = DataGetWarp(this, *index)

fun<T> DataGet<T>.asProxy( indexList:List<Int>)= DataGetWarp(this, indexList)